package com.shoulder.boot.system.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shoulder.boot.system.dto.DeptQueryDTO;
import com.shoulder.boot.system.entity.Dept;
import com.shoulder.boot.system.vo.DeptVo;
import com.shoulder.mybatis.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

public class DeptUtils implements PageUtils<Dept, DeptVo> {
    @Override
    public DeptVo toVo(Dept dept) {
        DeptVo vo = new DeptVo();
        BeanUtils.copyProperties(dept, vo);
        return vo;
    }

    public static LambdaQueryWrapper<Dept> buildQueryWrapper(DeptQueryDTO queryDTO) {
        LambdaQueryWrapper<Dept> queryWrapper = new LambdaQueryWrapper<Dept>().orderByDesc(Dept::getCreateTime);
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getName()), Dept::getName, queryDTO.getName());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getTenantId()), Dept::getTenantId, queryDTO.getTenantId());
        return queryWrapper;
    }

    public static DeptUtils buildUtils(){
        return new DeptUtils();
    }
}
